package proj1.util;

/**
 * <pre>
 * Utility methods for String manipulation.
 * </pre>
 * @author Jason Campos
 */
public class StringUtil {
	/**
	 * <pre>
	 * Returns {@code true} iff the argument string is null or its length is 0
	 * </pre>
	 * @param string The string being checked for null/empty
	 * @return {@code true} iff the argument string is null or its length is 0. {@code false} otherwise
	 */
	public static boolean isNullOrEmpty(String string){
		return (string == null || string.isEmpty());
	}
	
	/**
	 * <pre>
	 * If the argument 'string' {@link #isNullOrEmpty(String)}, returns 'defaultValue'. Otherwise,
	 * returns 'string'
	 * </pre>
	 * @param string The string being checked for null/empty
	 * @param defaultValue The default value to substitute when the 'string' argument is null/empty
	 * @return the argument 'string' {@link #isNullOrEmpty(String)}, returns 'defaultValue'. Otherwise,
	 * returns 'string'
	 */
	public static String ifNullOrEmpty(String string, String defaultValue){
		return isNullOrEmpty(string) ? defaultValue : string;
	}

	/**
	 * <pre>
	 * If the argument 'string' is {@code null}, returns 'defaultValue'
	 * </pre>
	 * @param string
	 * @param defaultValue
	 * @return If the argument 'string' is {@code null}, returns 'defaultValue'
	 */
	public static String ifNull(String string, String defaultValue) {
		return string == null ? defaultValue : string;
	}
}
